# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=sheldon
pkgver=0.7.4
pkgrel=0
pkgdesc="Fast, configurable, shell plugin manager"
url="https://github.com/rossmacarthur/sheldon"
arch="all"
license="MIT OR Apache-2.0"
makedepends="
	cargo
	cargo-auditable
	curl-dev
	libgit2-dev
	libssh2-dev
	openssl-dev
	"
subpackages="
	$pkgname-bash-completion
	$pkgname-zsh-completion
	"
source="https://github.com/rossmacarthur/sheldon/archive/$pkgver/sheldon-$pkgver.tar.gz"
options="net"

case "$CARCH" in
# FIXME: with libgit2-1.7 this segfaults in a specific test, but works fine at runtime
arm*|x86) options="$options !check" ;;
esac

export CARGO_PROFILE_RELEASE_OPT_LEVEL="z"
export LIBSSH2_SYS_USE_PKG_CONFIG=1  # use system libssh2

prepare() {
	default_prepare

	# Build against system libgit2.
	sed -i 's/"vendored-libgit2"//' Cargo.toml

	# Rust target triple.
	local target=$(rustc -vV | sed -n 's/host: //p')

	# Build against system-provided libs
	mkdir -p .cargo
	cat >> .cargo/config.toml <<-EOF
		[target.$target]
		git2 = { rustc-link-lib = ["git2"] }
	EOF

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --frozen --release
}

check() {
	# Skipped tests - https://github.com/rossmacarthur/sheldon/issues/140
	GIT_COMMIT_HASH="unknown" \
	GIT_COMMIT_SHORT_HASH="unknown" \
	GIT_COMMIT_DATE="unknown" \
	cargo test --frozen -- \
		--skip=lock_and_source_github_git \
		--skip=locked_config_clean \
		--skip=source_lock_git_git_with_checkout
}

package() {
	install -D -m755 target/release/sheldon -t "$pkgdir"/usr/bin/

	install -D -m644 completions/sheldon.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_sheldon
	install -D -m644 completions/sheldon.bash \
		"$pkgdir"/usr/share/bash-completion/completions/sheldon
}

sha512sums="
a07d7ed080fc55f5deebff12952148b14d14d6d46d02bff2e9f4d1e95e2390d7cefc4c5f7b1c28f1f8861f5999fb83141a01c42aaab2273a43d00104a0a1f70f  sheldon-0.7.4.tar.gz
"
